package com.ecloud.trend.utils;

import TrendDB.*;
import com.ecloud.trend.vo.TrendDataVo;
import com.ecloud.trend.vo.TrendHistPositionVo;
import com.ecloud.trend.vo.TrendHistStatusVo;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;

/**
 * Trend工具类
 *
 * @author Squbi
 * @date 2021/6/28 16:31
 */
public class TrendUtil {
    private TrendUtil() {
    }

    public static TrendHistPositionVo transfer(HistoryPosition historyPosition) {
        return new TrendHistPositionVo(
                API.FormatTime(historyPosition.start),
                API.FormatTime(historyPosition.current),
                API.FormatTime(historyPosition.end)
        );
    }

    public static TrendHistStatusVo transfer(HistoryStatus historyStatus) {
        return new TrendHistStatusVo(
                API.FormatTime(historyStatus.start),
                API.FormatTime(historyStatus.end)
        );
    }

    public static TrendDataVo transfer(DB_Value dbValue) {
        return new TrendDataVo(API.FormatTime(dbValue.time), dbValue.status, dbValue.value);
    }

    public static List<TrendDataVo> transfer(DB_Value[] dbValues) {
        List<TrendDataVo> data = new ArrayList<>();
        for (DB_Value dbValue : dbValues) {
            data.add(transfer(dbValue));
        }
        return data;
    }

    public static DB_Time transfer(LocalDateTime localDateTime) {
        long swap = localDateTime.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
        return API.LongToTime(swap);
    }
}
